import axios from 'axios';
import {Message} from 'element-ui';

const instance=axios.create({
    baseURL:'http://macio.ncyateng.com',
    timeout:5000,
});

instance.interceptors.request.use(
    (config)=>{
        console.log(config);
        return config;
    },
    (error)=>{
        console.log(error);
        return Promise.reject(error);
    }
);

instance.interceptors.response.use(
    (response)=>{
        console.log(response);
        let {data:{code}}=response;
        if(code==0){
            return response;
        }else if(code==1){
            Message({
                message:'系统繁忙',
                type:'warning',
            })
        }
    },
    (error)=>{
        console.log(error);
        Message({
            message:'系统错误',
            type:'error',
        });
        return Promise.reject(error);
    }
);

export default instance;